//
//  MasterViewController.m
//  Camara
//
//  Created by chenyunzhong on 16/6/19.
//  Copyright © 2016年 chenyunzhong. All rights reserved.
//

#import "MasterViewController.h"
#import "DetailViewController.h"
#import "TGDCamera.h"
#import <netdb.h>
#import <arpa/inet.h>

@interface MasterViewController (){
    TGDCamera *_camera;
    NSString *_callid;
    //TGDVideoConfView *_videoConfView;
    BOOL _isCreator;
    NSString *_memberIds;
    NSString *_callType;
    NSTimer *_requestInvitationTimer;
    NSString *_userId;
    NSString *_userAccount;
    NSString *_userPassword;
    NSString *_accountSid;
    NSString *_accountToken;
}

@end

@implementation MasterViewController

static MasterViewController* _instance = nil;

+(instancetype) shareInstance
{
    static dispatch_once_t onceToken ;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc] init] ;
    }) ;
    
    return _instance ;
}


+ (NSOperationQueue*)getQueue
{
    static NSOperationQueue* queue = NULL;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        queue = [[NSOperationQueue alloc] init];
    });
    return queue;
}

-(void)viewDidLoad{
    
    self.view.backgroundColor=[UIColor whiteColor];
    _camera = [TGDCamera cameraWithView:_playView];

    UIButton *btn=[[UIButton alloc] initWithFrame:CGRectMake(30, 350, 70, 40)];
    [btn setTitle:@"放大" forState:UIControlStateNormal];
    
    btn.backgroundColor=[UIColor redColor];
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    //[self.view addSubview:btn];
    
    
    UIButton *btn1=[[UIButton alloc] initWithFrame:CGRectMake(130, 350, 70, 40)];
    
    [btn1 setTitle:@"缩小" forState:UIControlStateNormal];
    
    btn1.backgroundColor=[UIColor redColor];
    [btn1 addTarget:self action:@selector(btnClick1:) forControlEvents:UIControlEventTouchUpInside];
}

-(NSString*)getIPAddressByHostName:(NSString*)strHostName
{
    const char* szname = [strHostName UTF8String];
    struct hostent* phot ;
    @try
    {
        phot = gethostbyname(szname);
    }
    @catch (NSException * e)
    {
        return nil;
    }
    
    struct in_addr ip_addr;
    memcpy(&ip_addr,phot->h_addr_list[0],4);///h_addr_list[0]里4个字节,每个字节8位，此处为一个数组，一个域名对应多个ip地址或者本地时一个机器有多个网卡
    
    char ip[20] = {0};
    inet_ntop(AF_INET, &ip_addr, ip, sizeof(ip));
    
    NSString* strIPAddress = [NSString stringWithUTF8String:ip];
    return strIPAddress;
}

-(IBAction) playerBtnClicked:(id)sender{
    NSString *ip =[self getIPAddressByHostName:@"hncshqm.xicp.net"];
    [_camera loginWithIpAddress:ip userName:@"admin" password:@"admin123"];
}

-(IBAction) stopBtnClicked:(id)sender
{
    [_camera stop];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Segues

@end
